import React, { VFC, useEffect, useState} from "react"
import { Select } from 'antd';
import { getTeamGroupAllList} from '@services/index';

const { Option } = Select;
type ItemType = {
    name:string
    id:number
}
const select:VFC<any> = props => {
    const {selectValue, onChange} = props;
    const [groupAllList, setGroupAllList] = useState<any[]>([]);
    const [defaultValue, setDefaultValue] = useState<any>('');

    useEffect(()=>{
        getTeamGroupData();
    },[]);
    useEffect(()=>{
        setDefaultValue(selectValue);
    },[selectValue]);
    // 获取小组列表 数据
    const getTeamGroupData= async () =>{
        const { data, status } = await getTeamGroupAllList()
        if(status === '0'){
            // data.unshift({id: '', name: '全部'});
            setGroupAllList(data);
        }
    }
    const onSelectChange = (e: any) => {
        setDefaultValue(e)
        onChange(e)
    }
    return (
        <Select value={defaultValue} style={{ width: 120 }} placeholder="请选择" onChange={onSelectChange}>
            {
                groupAllList.map((item:ItemType,index:number)=>{
                    return <Option value={item.id} key={index}>{item.name}</Option>
                })
            }
        </Select>
    )
}
export default select